<?php 
// 关闭顶部bar
add_filter('show_admin_bar', '__return_false');

// 导航;
register_nav_menus();

//小工具
if( function_exists('register_sidebar') ) {
    register_sidebar(array(
        'before_widget' => '<li class="widget">', // widget 的开始标签
        'after_widget' => '</li>', // widget 的结束标签
        'before_title' => '<h3>', // 标题的开始标签
        'after_title' => '</h3>' // 标题的结束标签
    ));
};

// 调用分类名称
function get_category_root_id($cat)
{
    $this_category = get_category($cat); // 取得当前分类
    while($this_category->category_parent) // 若当前分类有上级分类时，循环
    {
        $this_category = get_category($this_category->category_parent); // 将当前分类设为上级分类（往上爬）
    }
    return $this_category->term_id; // 返回根分类的id号
}

/*控制摘要字数*/
function new_excerpt_length($length) {
return 80;
}
add_filter("excerpt_length", "new_excerpt_length");

// 禁用谷歌字体
function coolwp_remove_open_sans_from_wp_core() {
wp_deregister_style( 'open-sans' );   
wp_register_style( 'open-sans', false );   
wp_enqueue_style('open-sans','');}
add_action( 'init', 'coolwp_remove_open_sans_from_wp_core' );

// 调用作者信息
function wp_list_authors($args = '') {
    global $wpdb;
    $defaults = array(
        'orderby' => 'name', 'order' => 'ASC', 'number' => '',
        'optioncount' => false, 'exclude_admin' => true,
        'show_fullname' => false, 'hide_empty' => true,
        'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true,
        'style' => 'list', 'html' => true, 'exclude' => '', 'include' => ''
    );

    $args = wp_parse_args( $args, $defaults );
    extract( $args, EXTR_SKIP );
    $return = '';

    $query_args = wp_array_slice_assoc( $args, array( 'orderby', 'order', 'number', 'exclude', 'include' ) );
    $query_args['fields'] = 'ids';
    $authors = get_users( $query_args );

    $author_count = array();
    foreach ( (array) $wpdb->get_results("SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE post_type = 'post' AND " . get_private_posts_cap_sql( 'post' ) . " GROUP BY post_author") as $row )
        $author_count[$row->post_author] = $row->count;

    foreach ( $authors as $author_id ) {
        $author = get_userdata( $author_id );

        if ( $exclude_admin && 'admin' == $author->display_name )
            continue;

        $posts = isset( $author_count[$author->ID] ) ? $author_count[$author->ID] : 0;

        if ( !$posts && $hide_empty )
            continue;

        $link = '';

        if ( $show_fullname && $author->first_name && $author->last_name )
            $name = "$author->first_name $author->last_name";
        else
            $name = $author->display_name;

        if ( !$html ) {
            $return .= $name . ', ';

            continue; // No need to go further to process HTML.
        }

        if ( 'list' == $style ) {
            $return .= '<li>';
        }

        $link = '<a href="' . get_author_posts_url( $author->ID, $author->user_nicename ) . '" title="' . esc_attr( sprintf(__("Posts by %s"), $author->display_name) ) . '">' . $name . '</a>';

        
        if ( $optioncount )
            $link .= ' ('. $posts . ')';

        $return .= $link;
        $return .= ( 'list' == $style ) ? '</li>' : ', ';
    }

    $return = rtrim($return, ', ');

    if ( !$echo )
        return $return;
    echo $return;
}

function wp_list_authors1($args = '') {
    global $wpdb;
    $defaults = array(
        'orderby' => 'name', 'order' => 'ASC', 'number' => '',
        'optioncount' => false, 'exclude_admin' => true,
        'show_fullname' => false, 'hide_empty' => true,
        'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true,
        'style' => 'list', 'html' => true, 'exclude' => '', 'include' => ''
    );

    $args = wp_parse_args( $args, $defaults );
    extract( $args, EXTR_SKIP );
    $return = '';

    $query_args = wp_array_slice_assoc( $args, array( 'orderby', 'order', 'number', 'exclude', 'include' ) );
    $query_args['fields'] = 'ids';
    $authors = get_users( $query_args );

    $author_count = array();
    foreach ( (array) $wpdb->get_results("SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE post_type = 'post' AND " . get_private_posts_cap_sql( 'post' ) . " GROUP BY post_author") as $row )
        $author_count[$row->post_author] = $row->count;

    foreach ( $authors as $author_id ) {
        $author = get_userdata( $author_id );

        if ( $exclude_admin && 'admin' == $author->display_name )
            continue;

        $posts = isset( $author_count[$author->ID] ) ? $author_count[$author->ID] : 0;

        if ( !$posts && $hide_empty )
            continue;

        $link = '';

        if ( $show_fullname && $author->first_name && $author->last_name )
            $name = "$author->first_name $author->last_name";
        else
            $name = $author->display_name;

        if ( !$html ) {
            $return .= $name . ', ';

            continue; // No need to go further to process HTML.
        }

        if ( 'list' == $style ) {
            $return .= '<li>';
        }

    
        if ( $optioncount )
            $link .= ' ('. $posts . ')';

        $return .= $link;
        $return .= ( 'list' == $style ) ? '</li>' : ', ';
    }

    $return = rtrim($return, ', ');

    if ( !$echo )
        return $return;
    echo $return;
}

?>